// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
  Await can await any thenable.
flags: [async]
---*/

function Test() {
    var error = {};
    var thenable = {
      then: function (resolve, reject) {
        throw error;
      }
    }
    async function foo() {
      var caught = false;
      try {
        await thenable;
      } catch(e) {
        caught = true;
        assert.sameValue(e, error);
      }

      assert(caught);
    }

    foo().then($DONE, $DONE);

}

// preheat
const NUMBER_OF_PREHEAT = 1;
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}

ArkTools.jitCompileAsync(Test);
assert.sameValue(ArkTools.waitJitCompileFinish(Test), true, '[JIT] JIT disabled.');

// test
const NUMBER_OF_TEST = 1; // or 2
for (let i = 0; i < NUMBER_OF_TEST; i++) {
    Test();
}
